<?php
 class Laporan extends CI_Controller{
 private $limit = 20;
    function  __construct() {
        parent::__construct();
        $this->load->model('Laporan_model');
		$this->load->model('User_model');
		$this->load->model('Cabang_model');
		$this->load->model('Cm_model');
		$this->load->model('Penjualan_model');
		$this->load->helper(array('html','form', 'url','jq_plugin'));
		$this->load->library(array('form_validation','pagination'));
		
	}
	
    function index(){
         if ($this->session->userdata('is_logged_in') == TRUE) {
                $this->load->view('admin_views/laporan/index');

             }
        else {
            redirect('login');
        }
    }
    function home(){
        $cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/laporan',$data);
    }
    function penjualan_harian()
	{
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
		$data['user'] = $cabang[0]->intid_user;
		$data['intid_privilege'] = $cabang[0]->intid_privilege;

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/param_harian',$data);
	}
	
	function cetak_harian()
	{
		$data['default'] = $this->Laporan_model->get_CetakPenjualanHarian($this->input->post('intid_cabang'),$this->input->post('tgl'));
        $this->load->view('admin_views/laporan/penjualan_harian', $data);
		
	}
	
	function penjualan_mingguan()
	{
		$week = $this->Laporan_model->selectWeek();
		foreach ($week as $g)
		{
			$data['id'][]	 	= $g->id;
			$data['intid_week'][] 	= $g->intid_week;
		}
		$jpenjualan = $this->Laporan_model->selectJPenjualan();
		foreach ($jpenjualan as $g)
		{
			$data['intid_jpenjualan'][]	 	= $g->intid_jpenjualan;
			$data['strnama_jpenjualan'][] 	= $g->strnama_jpenjualan;
		}
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
		$data['user'] = $cabang[0]->intid_user;
		$data['intid_privilege'] = $cabang[0]->intid_privilege;
		
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/param_mingguan', $data);
	}
	
	function cetak_mingguan()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$cabang = $nm_cabang[0]->intid_cabang;
		
		if ($this->input->post('intid_jpenjualan')==10)
		{ 
			$data['default'] = $this->Laporan_model->get_CetakPenjualanSKMingguan($this->input->post('intid_week'),$this->input->post('intid_cabang'));
			$this->load->view('admin_views/laporan/penjualan_skmingguan', $data);
		
		} else if ($this->input->post('intid_jpenjualan')==9)
		{ 
			$data['default'] = $this->Laporan_model->get_CetakPenjualanArisanMingguan($this->input->post('intid_week'),$this->input->post('intid_cabang'), $this->input->post('intid_jpenjualan'));
			$this->load->view('admin_views/laporan/penjualan_arisanmingguan', $data);
		} else {
			$data['default'] = $this->Laporan_model->get_CetakPenjualanMingguan($this->input->post('intid_week'),$this->input->post('intid_cabang'), $this->input->post('intid_jpenjualan'));
			$this->load->view('admin_views/laporan/penjualan_mingguan', $data);
		
		}
		
	}
	
	function penjualan_bulanan()
	{
		
		$jpenjualan = $this->Laporan_model->selectJPenjualan();
		foreach ($jpenjualan as $g)
		{
			$data['intid_jpenjualan'][]	 	= $g->intid_jpenjualan;
			$data['strnama_jpenjualan'][] 	= $g->strnama_jpenjualan;
		}
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
		$data['user'] = $cabang[0]->intid_user;
		$data['intid_privilege'] = $cabang[0]->intid_privilege;
		
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/param_bulanan', $data);
	}
	
	function cetak_bulanan()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$cabang = $nm_cabang[0]->intid_cabang;
		
		$data['month'] = $this->Laporan_model->get_Week($this->input->post('month'));
        $data['week_start'] = $this->Laporan_model->cek_bulan_start($this->input->post('month'));
		$data['week_end'] = $this->Laporan_model->cek_bulan_end($this->input->post('month'));
		if ($this->input->post('intid_jpenjualan')==10)
		{ 
			$data['default'] = $this->Laporan_model->get_CetakPenjualanSKBulanan($this->input->post('month'),$this->input->post('intid_cabang'));
			$this->load->view('admin_views/laporan/penjualan_skbulanan', $data);
		
		}else if ($this->input->post('intid_jpenjualan')==9)
		{ 
			$data['default'] = $this->Laporan_model->get_CetakPenjualanArisanBulanan($this->input->post('month'),$this->input->post('intid_cabang'));
			$this->load->view('admin_views/laporan/penjualan_arisanbulanan', $data);
		} else {
			$data['default'] = $this->Laporan_model->get_CetakPenjualanBulanan($this->input->post('month'),$this->input->post('intid_cabang'), $this->input->post('intid_jpenjualan'));
			
			$this->load->view('admin_views/laporan/penjualan_bulanan', $data);
		
		}
	}
	
	function keuangan(){
      
        $this->load->view('admin_views/laporan/keuangan');
    }
	
	function keuangan_harian(){
      
      	$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/param_keuharian', $data);
    }
	
	function cetak_keuharian()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['tgl'] = $this->input->post('tgl');
		$data['reguler'] = $this->Laporan_model->get_CetakKeuanganHarianReguler($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['hut'] = $this->Laporan_model->get_CetakKeuanganHarianHut($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['challenge'] = $this->Laporan_model->get_CetakKeuanganHarianChallenge($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['trade'] = $this->Laporan_model->get_CetakKeuanganHarianTrade($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['freehut'] = $this->Laporan_model->get_CetakKeuanganHarianFreeHut($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['free'] = $this->Laporan_model->get_CetakKeuanganHarianFree($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['netto'] = $this->Laporan_model->get_CetakKeuanganHarianNetto($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['jlain'] = $this->Laporan_model->get_CetakKeuanganHarianLain($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['arisan'] = $this->Laporan_model->get_CetakKeuanganHarianArisan($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['komisi'] = $this->Laporan_model->get_CetakKeuanganHarianKomisi($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['dp'] = $this->Laporan_model->get_CetakKeuanganHarianDP($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$data['komisiarisan'] = $this->Laporan_model->get_CetakKeuanganHarianKomisiArisan($this->input->post('intid_cabang'),$this->input->post('tgl'));
		$this->load->view('admin_views/laporan/keuangan_harian', $data);
		
	}
	
	function keuangan_mingguan(){
      
      	$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
		$data['user'] = $cabang[0]->intid_user;
		$data['intid_privilege'] = $cabang[0]->intid_privilege;
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$week = $this->Laporan_model->selectWeek();
		foreach ($week as $g)
		{
			$data['id'][]	 	    = $g->id;
			$data['intid_week'][] 	= $g->intid_week;
		}
		
		$this->load->view('admin_views/laporan/param_keumingguan', $data);
    }
	
		
	function cetak_keumingguan()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['reguler'] = $this->Laporan_model->get_CetakKeuanganMingguanReguler($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['hut'] = $this->Laporan_model->get_CetakKeuanganMingguanHut($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['challenge'] = $this->Laporan_model->get_CetakKeuanganMingguanChallenge($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['trade'] = $this->Laporan_model->get_CetakKeuanganMingguanTrade($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['freehut'] = $this->Laporan_model->get_CetakKeuanganMingguanFreeHut($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['free'] = $this->Laporan_model->get_CetakKeuanganMingguanFree($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['netto'] = $this->Laporan_model->get_CetakKeuanganMingguanNetto($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['sk'] = $this->Laporan_model->get_CetakKeuanganMingguanSK($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['jlain'] = $this->Laporan_model->get_CetakKeuanganMingguanLain($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['spesial'] = $this->Laporan_model->get_CetakKeuanganMingguanSpecialPrice($this->input->post('intid_cabang'),$this->input->post('intid_week'));
//001
		$data['point'] = $this->Laporan_model->get_CetakKeuanganMingguanPoint($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['metal50'] = $this->Laporan_model->get_CetakKeuanganMingguanMetal50($this->input->post('intid_cabang'),$this->input->post('intid_week'));

		$data['komisi'] = $this->Laporan_model->get_CetakKeuanganMingguanKomisi($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['week'] = $this->Laporan_model->get_DateWeek($this->input->post('intid_week'));
		$data['pembayaran'] = $this->Laporan_model->selectPembayaranMingguan($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['total_bayar'] = $this->Laporan_model->selectTotalPembayaranMingguan($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['total_bayartrade'] = $this->Laporan_model->selectTotalPembayaranMingguanTrade($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['sudah_bayar'] = $this->Laporan_model->selectTotalBayarMingguan($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['dp'] = $this->Laporan_model->get_CetakKeuanganMingguanDP($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['komisiarisan'] = $this->Laporan_model->get_CetakKeuanganMingguanKomisiArisan($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['arisan'] = $this->Laporan_model->get_CetakKeuanganMingguanArisan($this->input->post('intid_cabang'),$this->input->post('intid_week'));
		$data['lunasdp'] = $this->Laporan_model->selectTotalDpLunasMingguan($this->input->post('intid_cabang'),$this->input->post('intid_week'));		
		$this->load->view('admin_views/laporan/keuangan_mingguan', $data);
		
	}
	
	function pembayaran()
	{
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$data['default'] = $this->Laporan_model->selectPembayaran($nm_cabang[0]->intid_cabang);
        $this->load->view('admin_views/laporan/pembayaran', $data);
		
	}
	
	function save_pembayaran() {
		
		$this->Laporan_model->insertPembayaran($_POST);
		redirect('laporan/pembayaran');
	
	}
	
	function keuangan_bulanan(){
      
      	$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
		$data['user'] = $cabang[0]->intid_user;
		$data['intid_privilege'] = $cabang[0]->intid_privilege;
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
				
		$this->load->view('admin_views/laporan/param_keubulanan', $data);
    }
	
		
	function cetak_keubulanan()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['reguler'] = $this->Laporan_model->get_CetakKeuanganBulananReguler($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['hut'] = $this->Laporan_model->get_CetakKeuanganBulananHut($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['challenge'] = $this->Laporan_model->get_CetakKeuanganBulananChallenge($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['trade'] = $this->Laporan_model->get_CetakKeuanganBulananTrade($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['freehut'] = $this->Laporan_model->get_CetakKeuanganBulananFreeHut($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['free'] = $this->Laporan_model->get_CetakKeuanganBulananFree($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['netto'] = $this->Laporan_model->get_CetakKeuanganBulananNetto($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['sk'] = $this->Laporan_model->get_CetakKeuanganBulananSK($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['jlain'] = $this->Laporan_model->get_CetakKeuanganBulananLain($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['spesial'] = $this->Laporan_model->get_CetakKeuanganBulananSpesial($this->input->post('intid_cabang'),$this->input->post('month'));
//001
		$data['point'] = $this->Laporan_model->get_CetakKeuanganBulananPoint($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['metal50'] = $this->Laporan_model->get_CetakKeuanganBulananMetal50($this->input->post('intid_cabang'),$this->input->post('month'));
		
		$data['komisi'] = $this->Laporan_model->get_CetakKeuanganBulananKomisi($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['month'] = $this->Laporan_model->get_Week($this->input->post('month'));
		$data['pembayaran'] = $this->Laporan_model->selectPembayaranBulanan($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['total_bayar'] = $this->Laporan_model->selectTotalPembayaranBulanan($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['total_bayartrade'] = $this->Laporan_model->selectTotalPembayaranBulananTrade($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['sudah_bayar'] = $this->Laporan_model->selectTotalBayarBulanan($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['week_start'] = $this->Laporan_model->cek_bulan_start($this->input->post('month'));
		$data['week_end'] = $this->Laporan_model->cek_bulan_end($this->input->post('month'));
		$data['dp'] = $this->Laporan_model->get_CetakKeuanganBulananDP($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['komisiarisan'] = $this->Laporan_model->get_CetakKeuanganBulananKomisiArisan($this->input->post('intid_cabang'),$this->input->post('month'));
		$data['arisan'] = $this->Laporan_model->get_CetakKeuanganBulananArisan($this->input->post('intid_cabang'),$this->input->post('month'));
		$this->load->view('admin_views/laporan/keuangan_bulanan', $data);
		
	}
	
	
	function pv(){
      
     $this->load->view('admin_views/laporan/param_pv');
     
    }
	
	
	function excelPv() {
		
		$this->get_report('excel_pv');
	}
	
	function boom(){
        $cabang = $this->User_model->getCabang($this->session->userdata('username'));
            $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

            $data['cabang'] = $nm_cabang[0]->strnama_cabang;
            $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
	
      $this->load->view('admin_views/laporan/param_boom',$data);
    }

    function excel() {
		$this->get_report('excel');
	}
	
	
	function get_report($menu){
          $data['parent'] = $this->input->post('strkode_dealer');
          $data['unit'] = $this->input->post('id_unit');
		  $data['tglstart'] = $this->input->post('tglstart');
		  $data['tglend'] = $this->input->post('tglend');
          $start = $this->Laporan_model->getTotalParent($this->input->post('strkode_dealer'));
		   $pilihan = $this->input->post('pilihan');
			$data['mulai'] = $start[0]->intlevel_dealer;
		  $data['member'] = $this->Cm_model->getMember($this->input->post('strkode_dealer'));
		  $data['jumLevel'] = $this->jum_children($this->input->post('strkode_dealer'), $data['mulai']);
        if($menu=='excel'){
			if($pilihan == 1){
            	$this->load->view('admin_views/laporan/boom', $data);
				}elseif($pilihan == 2){
				//$this->load->view('admin_views/laporan/boom_omset', $data);
				$this->print_boom_cm_ranting();
			}elseif($pilihan == 3){
				$this->print_boom_cm_ranting();
			}
        } else if($menu=='excel_pv'){
            $this->load->view('admin_views/laporan/pv', $data);
        }
    }
	
     function ranting() {
        if($this->input->post('ajax') == '1') {

            $this->form_validation->set_rules('strkode_dealer', 'Nama', 'trim|required|xss_clean');
            $this->form_validation->set_message('required', 'Please fill in the fields');
            if($this->form_validation->run() == FALSE) {
                echo validation_errors();
            } else {
                $data['strnama_dealer'] = $this->Cm_model->getMember($this->input->post('strkode_dealer'));
                $data['strkode_upline'] = $this->input->post('strkode_dealer');

                $this->load->view('admin_views/laporan/ranting', $data);
            }
        }
        
    }
	
	function overiding() {

        $this->load->view('admin_views/laporan/or');
    }

    function nama_bulan($bulan) {
	$b="";
        switch ($bulan) {
            case '1':
                $b = "Januari";
                break;
            case '2':
                $b = "Februari";
                break;
            case '3':
                $b = "Maret";
                break;
            case '4':
                $b = "April";
                break;
            case '5':
                $b = "Mei";
                break;
            case '6':
                $b = "Juni";
                break;
            case '7':
                $b = "Juli";
                break;
            case '8':
                $b = "Agustus";
                break;
            case '9':
                $b = "September";
                break;
            case '10':
                $b = "Oktober";
                break;
            case '11':
                $b = "November";
                break;
            case '12':
                $b = "Desember";
                break;

        }

        return $b;

    }

    function ordealer() {
        
        $cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
			
		if($_POST) {
            
            $id_cabang = $this->input->post('intid_cabang');
			$bulan = $this->input->post('month');
			$data['bulan'] = $bulan;
            $data['nama_bulan'] = $bulan;
            $data['belanjadealer'] = $this->Penjualan_model->get_dealer_unit($bulan);
			//$belanjadealer = $this->Penjualan_model->get_dealer_unit($bulan);
			//$strkode_upline = $belanjadealer[0]->strkode_dealer;
			//$data['data_pv_dealer']= $this->Penjualan_model->ordealer_member($strkode_upline, $bulan);
            $this->load->view('admin_views/laporan/view_ordealer', $data);
        }else {
            
            $this->load->view('admin_views/laporan/param_ordealer', $data);
        }
    }
	/*
	function ormanager() {
        if($_POST) {
            $bulan = $this->input->post('month');
            $nama_bulan = $this->nama_bulan($bulan);
			$data['nama_bulan'] = $nama_bulan;
			$data['bulan'] = $bulan;
			$data['data_or_manager'] = $this->Penjualan_model->get_manager_unit($bulan);
						
			$a = $bulan + 1;
			if($a == 13) {
				$b = 1;
			}else {
				$b = $a;
			}
			$aa = $bulan + 2;
			if($aa == 14) {
				$c = 2;
			}else {
				$c = $aa;
			}
			
			$nama_bulan = $this->nama_bulan($bulan);
			$nama_bulan1 = $this->nama_bulan($b);
			$nama_bulan2 = $this->nama_bulan($c);
			$thn = date('Y');
			$data['weeks'] = $this->Cm_model->cek_bulan($bulan, $thn);
           
            $this->load->view('admin_views/laporan/view_ormanager', $data);
        }else{
            $this->load->view('admin_views/laporan/param_ormanager');
        }
    }
	*/
	/////fungsi ormanager yang baru line ikhlas 09042013///////
	function ormanager() {
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
			
		if($_POST) {
			if($data['id_cabang'] == 1){
            $bulan = $this->input->post('month');
            $nama_bulan = $this->nama_bulan($bulan);
			$data['nama_bulan'] = $nama_bulan;
			$data['bulan'] = $bulan;
			$data['data_or_manager'] = $this->Penjualan_model->get_manager_unit($bulan);
						
			$a = $bulan + 1;
			if($a == 13) {
				$b = 1;
			}else {
				$b = $a;
			}
			$aa = $bulan + 2;
			if($aa == 14) {
				$c = 2;
			}else {
				$c = $aa;
			}
			
			$nama_bulan = $this->nama_bulan($bulan);
			$nama_bulan1 = $this->nama_bulan($b);
			$nama_bulan2 = $this->nama_bulan($c);
			$thn = date('Y');
			$data['weeks'] = $this->Cm_model->cek_bulan($bulan, $thn);
           }else{
			$bulan = $this->input->post('month');
            $nama_bulan = $this->nama_bulan($bulan);
			$data['nama_bulan'] = $nama_bulan;
			$data['bulan'] = $bulan;
			$data['data_or_manager'] = $this->Penjualan_model->get_manager_unit_cabang($bulan,$data['id_cabang']);
						
			$a = $bulan + 1;
			if($a == 13) {
				$b = 1;
			}else {
				$b = $a;
			}
			$aa = $bulan + 2;
			if($aa == 14) {
				$c = 2;
			}else {
				$c = $aa;
			}
			$data['bulan'] = $bulan;
			$nama_bulan = $this->nama_bulan($bulan);
			$nama_bulan1 = $this->nama_bulan($b);
			$nama_bulan2 = $this->nama_bulan($c);
			$thn = date('Y');
			$data['weeks'] = $this->Cm_model->cek_bulan($bulan, $thn);
           
		   }
            $this->load->view('admin_views/laporan/view_ormanager', $data);
        }else{
            $this->load->view('admin_views/laporan/param_ormanager',$data);
        }
    }
///////////////////end/////////
    function cetak_ormanager() {

        $this->load->view('admin_views/laporan/param_cetakorm');
    }
	
	function print_or_manager() {
		$tahun = date('Y');
        $kode_dealer = $this->input->post('strkode_dealer');
		$bulan = $this->input->post('bulan');
		$data['nama_bulan'] = $this->nama_bulan($bulan);
		$data_omset = $this->Penjualan_model->get_Omset($kode_dealer, $bulan);
        $data['data_pv_manager'] = $this->Penjualan_model->get_unit_or($kode_dealer, $bulan, $data_omset[0]->intid_unit);
		$data['data_omset'] = $this->Penjualan_model->get_Omset($kode_dealer, $bulan);
		$data['data_omset_group'] = $this->Penjualan_model->get_Omset_Group($kode_dealer, $bulan);
        $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($kode_dealer);
		$data['rekrut'] = $this->Penjualan_model->getRekrut($kode_dealer, $bulan);
		$data['id_bulan'] = $bulan;
		$this->load->view('admin_views/laporan/print_or_manager', $data);

    }

    function cetak_ordealer() {

        $this->load->view('admin_views/laporan/param_cetakord');
    }

    function print_or_dealer() {
        $this->load->model('PO_model_1','PO_M');
		
		$kode_dealer =  $this->input->post('strkode_dealer');
		$bulan =  $this->input->post('bulan');
		$data['nama_bulan'] = $this->nama_bulan($bulan);
        $data['data_pv_dealer'] = $this->Penjualan_model->get_PV($kode_dealer, $bulan);
		$data['data_omset'] = $this->Penjualan_model->get_Omset($kode_dealer, $bulan);
        $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($kode_dealer);
		
			$datatemp['month']	=	$bulan;
			$data['get_periode'] = $this->PO_M->get_periode($datatemp);
        $this->load->view('admin_views/laporan/print_or_dealer', $data);

    }
	
	function fee() {

        $this->load->view('admin_views/laporan/fee');
    }
	
	function feekc() {

        $this->load->view('admin_views/laporan/feekc');
    }
	
	function feebabykc(){
      if($_POST){
       	
		$data['id_cabang'] = $this->input->post('intid_cabang');
		$data['nama_cabang'] = $this->input->post('id_cabang');
		$data['bulan'] = $this->input->post('month');
		$data['nama_unit'] = $this->input->post('nama_unit');
        $data['nama_bulan'] = $this->nama_bulan($data['bulan']);
            
		     //reguler
            $data['Reg'] = $this->Penjualan_model->get_reguler($data['id_cabang'], $data['bulan']);
            $data['RegDealer'] = $this->Penjualan_model->get_reguler_dealer($data['id_cabang'], $data['bulan']);

            //Hut
            $data['Hut'] = $this->Penjualan_model->get_hut($data['id_cabang'], $data['bulan']);
            $data['HutDealer'] = $this->Penjualan_model->get_hut_dealer($data['id_cabang'], $data['bulan']);
			
			//Challenge
            $data['Cal'] = $this->Penjualan_model->get_cal($data['id_cabang'], $data['bulan']);
            $data['CalDealer'] = $this->Penjualan_model->get_cal_dealer($data['id_cabang'], $data['bulan']);
			
			//Trade In
            $data['tin'] = $this->Penjualan_model->get_tin($data['id_cabang'], $data['bulan']);
            $data['tinDealer'] = $this->Penjualan_model->get_tin_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 Hut
            $data['ifi'] = $this->Penjualan_model->get_ifi($data['id_cabang'], $data['bulan']);
            $data['ifiDealer'] = $this->Penjualan_model->get_ifi_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 
            $data['ifo'] = $this->Penjualan_model->get_ifo($data['id_cabang'], $data['bulan']);
            $data['ifoDealer'] = $this->Penjualan_model->get_ifo_dealer($data['id_cabang'], $data['bulan']);

			//Netto 
            $data['net'] = $this->Penjualan_model->get_net($data['id_cabang'], $data['bulan']);
            $data['netDealer'] = $this->Penjualan_model->get_net_dealer($data['id_cabang'], $data['bulan']);
			
			//SpecialPrice 
            $data['sp'] = $this->Penjualan_model->get_sp($data['id_cabang'], $data['bulan']);
            $data['spDealer'] = $this->Penjualan_model->get_sp_dealer($data['id_cabang'], $data['bulan']);
			
			//Point 
            $data['p'] = $this->Penjualan_model->get_p($data['id_cabang'], $data['bulan']);
            $data['pDealer'] = $this->Penjualan_model->get_p_dealer($data['id_cabang'], $data['bulan']);

		
		$data['data_cabang'] = $this->Penjualan_model->get_cabang($this->input->post('intid_cabang'), $data['bulan']);
		$data['data_cabang'] = $this->Penjualan_model->get_cabang($this->input->post
('intid_cabang'));
		
		$this->load->view('admin_views/laporan/print_babycabang', $data);
	  }else{
      	$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
				
		$this->load->view('admin_views/laporan/param_fbabykc', $data);	  
	  }
    }
	
	function fkc(){
       if($_POST) {
            $data['id_cabang'] = $this->input->post('intid_cabang');
            $data['nama_cabang'] = $this->input->post('id_cabang');
            $data['bulan'] = $this->input->post('month');
            $data['parent'] = $this->input->post('strkode_dealer');
            $data['unit'] = $this->input->post('id_unit');
            $data['nama_unit'] = $this->input->post('nama_unit');
            $data['nama_bulan'] = $this->nama_bulan($data['bulan']);
            $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($data['parent']);
			
            //reguler
            $data['Reg'] = $this->Penjualan_model->get_reguler($data['id_cabang'], $data['bulan']);
            $data['RegDealer'] = $this->Penjualan_model->get_reguler_dealer($data['id_cabang'], $data['bulan']);

            //Hut
            $data['Hut'] = $this->Penjualan_model->get_hut($data['id_cabang'], $data['bulan']);
            $data['HutDealer'] = $this->Penjualan_model->get_hut_dealer($data['id_cabang'], $data['bulan']);
			
			//Challenge
            $data['Cal'] = $this->Penjualan_model->get_cal($data['id_cabang'], $data['bulan']);
            $data['CalDealer'] = $this->Penjualan_model->get_cal_dealer($data['id_cabang'], $data['bulan']);
			
			//Trade In
            $data['tin'] = $this->Penjualan_model->get_tin($data['id_cabang'], $data['bulan']);
            $data['tinDealer'] = $this->Penjualan_model->get_tin_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 Hut
            $data['ifi'] = $this->Penjualan_model->get_ifi($data['id_cabang'], $data['bulan']);
            $data['ifiDealer'] = $this->Penjualan_model->get_ifi_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 
            $data['ifo'] = $this->Penjualan_model->get_ifo($data['id_cabang'], $data['bulan']);
            $data['ifoDealer'] = $this->Penjualan_model->get_ifo_dealer($data['id_cabang'], $data['bulan']);

			//Netto 
            $data['net'] = $this->Penjualan_model->get_net($data['id_cabang'], $data['bulan']);
            $data['netDealer'] = $this->Penjualan_model->get_net_dealer($data['id_cabang'], $data['bulan']);
			
			//SpecialPrice 
            $data['sp'] = $this->Penjualan_model->get_sp($data['id_cabang'], $data['bulan']);
            $data['spDealer'] = $this->Penjualan_model->get_sp_dealer($data['id_cabang'], $data['bulan']);
			
			//Point 
            $data['p'] = $this->Penjualan_model->get_p($data['id_cabang'], $data['bulan']);
            $data['pDealer'] = $this->Penjualan_model->get_p_dealer($data['id_cabang'], $data['bulan']);

//001
			//Metal 50% 
            $data['m50'] = $this->Penjualan_model->get_m50($data['id_cabang'], $data['bulan']);
            $data['m50Dealer'] = $this->Penjualan_model->get_m50_dealer($data['id_cabang'], $data['bulan']);

			$data['getFeeSc'] = $this->Penjualan_model->get_dealer_cabang($this->input->post('intid_cabang'), $data['bulan']);
			$data['data_cabang'] = $this->Penjualan_model->get_cabang($this->input->post('intid_cabang'));
			
            $this->load->view('admin_views/laporan/print_fee_kc', $data);
			
        }else {
      	$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
				
		$this->load->view('admin_views/laporan/param_fkc', $data);
		}
    }
/*
-------------------------------------------------------------
program yang buat ikhlas batman 25MARET 2013
-------------------------------------------------------------
*/
	function fkc_baby(){
		$this->load->model('TampilkanFKC');
            
 	if($_POST) {
			
			$data['id_cabang'] = $this->input->post('intid_cabang');
            $data['nama_cabang'] = $this->input->post('id_cabang');
            $data['bulan'] = $this->input->post('month');
            $data['parent'] = $this->input->post('strkode_dealer');
            $data['unit'] = $this->input->post('id_unit');
            $data['nama_unit'] = $this->input->post('nama_unit');
            $data['nama_bulan'] = $this->nama_bulan($data['bulan']);
            $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($data['parent']);
			$data['tab0'] = 0;
            $data['tab5'] = 0;
            $data['tab1'] = 0;
            $data['tab2'] = 0;
            $data['tab3'] = 0;
            $data['tab4'] = 0;
			$data['prs'] = 0;
			
			$this->load->view('admin_views/laporan/print_fee_kc_baby_head', $data);
			$data['result'] = $this->TampilkanFKC->get_baby_fields($data['id_cabang']);
			
					$this->load->view('admin_views/laporan/print_fee_kc_baby_body_dif', $data);					
					/*										
					foreach ($data['Reg'] as $row){
					     $omsetreg20= $omsetreg20 + $row->TGroup20;
						 $omsetreg10= $omsetreg10 + $row->TGroup10;
					}
					foreach ($data['RegDealer'] as $row1){
							 $omsetdealerreg= $omsetdealerreg + $row1->RegDealer;
					}
					$hdealer = ($omsetreg20 - ($omsetreg20*0.2)) + ($omsetreg10 - ($omsetreg10*0.1));					
					if(!empty($hdealer)){
						$regD = $hdealer;
						$har_reg =  (($hdealer) * $data['prs']/100) - (($hdealer* $data['prs']/100) * 5/100);
					}

					foreach ($data['Hut'] as $row2){
							 $omsethut20= $omsethut20 + $row2->TGroup20;
							 $omsethut10= $omsethut10 + $row2->TGroup10;
					}
					foreach ($data['HutDealer'] as $row3){
							 $omsetdealerhut= $omsetdealerhut + $row3->HutDealer;
						}
					$hdealerhut = ($omsethut20 - ($omsethut20*0.2)) + ($omsethut10 - ($omsethut10*0.1));
					
					if(!empty($hdealerhut)){
						$hutD = $hdealerhut;
						$har_hut = (($hdealerhut) * $data['prs']/100) - (($hdealerhut* $data['prs']/100) * 5/100);
					}
					
					foreach ($data['Cal'] as $row4){
							 $omsettulipcal20= $omsettulipcal20 + $row4->TGroup20;
							 $omsettulipcal10= $omsettulipcal10 + $row4->TGroup10;
					}	
					foreach ($data['CalDealer'] as $row5){
							 $omsetdealercal= $omsetdealercal + $row5->CalDealer;
					}
					$hdealercal = ($omsettulipcal20 - ($omsettulipcal20*0.2)) + ($omsettulipcal10 - ($omsettulipcal10*0.1));
					
					if(!empty($hdealercal)){
						$calD = $hdealercal;
						$har_cal = (($hdealercal) * $data['prs']/100) - (($hdealercal* $data['prs']/100) * 5/100);
					}
					
					foreach ($data['tin'] as $row6){
							 $omsettin20= $omsettin20 + $row6->TGroup20;
							 $omsettin10= $omsettin10 + $row6->TGroup10;
					}
					foreach ($data['tinDealer'] as $row7){
							 $omsetdealertin= $omsetdealertin + $row7->tinDealer;
					}
					$hdealertin = ($omsettin20 - ($omsettin20*0.2)) + ($omsettin10 - ($omsettin10*0.1));
					if(!empty($hdealertin)){
						$tinD = $hdealertin;
						$har_tin = (($hdealertin) * $data['prs']/100) - (($hdealertin* $data['prs']/100) * 5/100);
					}

					foreach ($data['ifi'] as $row8){
							 $omsetifi= $omsetifi + $row8->inttotal_omset;
					}
					foreach ($data['ifiDealer'] as $row9){
							 $omsetdealerifi= $omsetdealerifi + $row9->ifiDealer;
					}					
					if(!empty($omsetdealerifi)){
						$ifiD = $omsetdealerifi;
						$har_ifi = (($omsetdealerifi) * $data['prs']/100) - (($omsetdealerifi* $data['prs']/100) * 5/100);
					}
					
					foreach ($data['ifo'] as $row10){
							 $omsetifo10= $omsetifo10 + $row10->TGroup10;
					}
					foreach ($data['ifoDealer'] as $row11){
							 $omsetdealerifo= $omsetdealerifo + $row11->ifoDealer;
					}
					
					$hdealerifo = ($omsetifo10 - ($omsetifo10*0.1));
					
					if(!empty($hdealerifo)){
						$ifoD = $hdealerifo;
						$har_ifo = (($hdealerifo) * $data['prs']/100) - (($hdealerifo* $data['prs']/100) * 5/100);
					}
					foreach ($data['net'] as $row12){
							 $omsetnet= $omsetnet + $row12->inttotal_omset;
					}
					foreach ($data['netDealer'] as $row13){
							 $omsetdealernet= $omsetdealernet + $row13->netDealer;
					}
					if(!empty($omsetdealernet)){
						$netD = $omsetdealernet;
						$har_net = (($omsetdealernet) * $data['prs']/100) - (($omsetdealernet* $data['prs']/100) * 5/100);
					}
					foreach ($data['sp'] as $row14){
							 $omsetsp= $omsetsp + $row14->inttotal_omset;
					}
					foreach ($data['spDealer'] as $row15){
							 $omsetdealersp= $omsetdealersp + $row15->netDealer;
					}	 
					
					if(!empty($omsetdealersp)){
						$spD = $omsetdealersp;
						$har_sp = (($omsetdealersp) * $data['prs']/100) - (($omsetdealersp* $data['prs']/100) * 5/100);
					}
					foreach ($data['p'] as $row16){
							 $omsetp= $omsetp + $row16->inttotal_omset;
						}
					foreach ($data['pDealer'] as $row31){
							 $omsetdealerp= $omsetdealerp + $row31->netDealer;
					}
					if(!empty($omsetdealerp)){
						$pD = $omsetdealerp;
						$har_p = (($omsetdealerp) * $data['prs']/100) - (($omsetdealerp* $data['prs']/100) * 5/100);
					}
					$data['tab0'] = $data['tab0'] + $omsetp;
					$data['tab5'] = $data['tab5'] + $omsetdealerp;
					$data['tab1'] = $data['tab1'] + ($regD + $hutD + $calD + $tinD + $ifiD + $ifoD + $netD + $spD + $pD);
					$data['tab2'] = $data['tab2'] + (($regD * $data['prs'] / 100) + ($hutD * $data['prs'] / 100) + ($calD * $data['prs']/ 100) + ($tinD * $data['prs']/ 100)+ ($ifiD * $data['prs']/ 100)+ ($ifoD * $data['prs']/ 100)+ ($netD * $data['prs']/ 100) + ($spD * $data['prs']/ 100) + ($pD * $data['prs']/ 100));
					$data['tab3'] = $data['tab3'] + ((($regD * $data['prs']/100) * 5/100) + (($hutD * $data['prs']/100)*5/100) + (($calD * $data['prs']/100) * 5/ 100) + (($tinD * $data['prs']/100 )* 5/ 100)+ (($ifiD * $data['prs']/100) * 5/ 100)+ (($ifoD * $data['prs']/100) * 5/ 100)+ (($netD * $data['prs']/100) * 5/ 100) + (($spD * $data['prs']/100) * 5/ 100) + (($pD * $data['prs']/100) * 5/ 100));
					$data['tab4'] = $data['tab4'] + ($har_hut + $har_reg + $har_cal + $har_tin + $har_ifi+ $har_ifo+ $har_net + $har_sp + $har_p);
					*/
					/*
				///reguler//
				foreach ($data['Reg'] as $row):
					     $omsetreg20= $omsetreg20 + $row->TGroup20;
						 $omsetreg10= $omsetreg10 + $row->TGroup10;
				endforeach;	
				foreach ($data['RegDealer'] as $row1):
					     $omsetdealerreg= $omsetdealerreg + $row1->RegDealer;
				endforeach;	 
				$hdealer = ($omsetreg20 - ($omsetreg20*0.2)) + ($omsetreg10 - ($omsetreg10*0.1));
				if(!empty($hdealer)){
						$regD = $hdealer;
						$har_reg =  (($hdealer) * $data['prs'] /100) - (($hdealer*$data['prs'] /100) * 5/100);
					}
				////HUT////
				foreach ($data['Hut'] as $row2):
					     $omsethut20= $omsethut20 + $row2->TGroup20;
						 $omsethut10= $omsethut10 + $row2->TGroup10;
				endforeach;	
				foreach ($data['HutDealer'] as $row3):
					     $omsetdealerhut= $omsetdealerhut + $row3->HutDealer;
				endforeach;	 
				 $hdealerhut = ($omsethut20 - ($omsethut20*0.2)) + ($omsethut10 - ($omsethut10*0.1));
				 if(!empty($hdealerhut)){
						$hutD = $hdealerhut;
						$har_hut = (($hdealerhut) * $prs/100) - (($hdealerhut* $prs/100) * 5/100);
					}
				//////challl
				 foreach ($data['Cal'] as $row4):
					     $omsettulipcal20= $omsettulipcal20 + $row4->TGroup20;
						 $omsettulipcal10= $omsettulipcal10 + $row4->TGroup10;
				endforeach;	
				foreach ($data['CalDealer'] as $row5):
					     $omsetdealercal= $omsetdealercal + $row5->CalDealer;
				endforeach;	 
				$hdealercal = ($omsettulipcal20 - ($omsettulipcal20*0.2)) + ($omsettulipcal10 - ($omsettulipcal10*0.1));
				if(!empty($hdealercal)){
						$calD = $hdealercal;
						$har_cal = (($hdealercal) * $prs/100) - (($hdealercal* $prs/100) * 5/100);
						echo (empty($har_cal))?'0':number_format($har_cal);
					}
				///tin////////
				foreach ($data['tin'] as $row6):
					     $omsettin20= $omsettin20 + $row6->TGroup20;
						 $omsettin10= $omsettin10 + $row6->TGroup10;
				endforeach;	
				foreach ($data['tinDealer']  as $row7):
					     $omsetdealertin= $omsetdealertin + $row7->tinDealer;
				endforeach;
				$hdealertin = ($omsettin20 - ($omsettin20*0.2)) + ($omsettin10 - ($omsettin10*0.1));				
				///TOTAL
					$data['tab1'] = $data['tab1'] + ($regD + $hutD + $calD + $tinD + $ifiD + $ifoD + $netD + $spD + $pD);
					$data['tab2'] = $data['tab2'] + (($regD * $data['prs'] / 100) + ($hutD * $data['prs'] / 100) + ($calD * $data['prs']/ 100) + ($tinD * $data['prs']/ 100)+ ($ifiD * $data['prs']/ 100)+ ($ifoD * $data['prs']/ 100)+ ($netD * $data['prs']/ 100) + ($spD * $data['prs']/ 100) + ($pD * $data['prs']/ 100));
					$data['tab3'] = $data['tab3'] + ((($regD * $data['prs']/100) * 5/100) + (($hutD * $data['prs']/100)*5/100) + (($calD * $data['prs']/100) * 5/ 100) + (($tinD * $data['prs']/100 )* 5/ 100)+ (($ifiD * $data['prs']/100) * 5/ 100)+ (($ifoD * $data['prs']/100) * 5/ 100)+ (($netD * $data['prs']/100) * 5/ 100) + (($spD * $data['prs']/100) * 5/ 100) + (($pD * $data['prs']/100) * 5/ 100));
					$data['tab4'] = $data['tab4'] + ($har_hut + $har_reg + $har_cal + $har_tin + $har_ifi+ $har_ifo+ $har_net + $har_sp + $har_p);
					*/
				
				
			$this->load->view('admin_views/laporan/print_fee_kc_baby_footer', $data);	
	}else {
      	$cabang = $this->User_model->getCabang($this->session->userdata('username'));
		if($this->session->userdata('username') == "admin"){
				$data['show_table'] = $this->TampilkanFKC->Tampilkan_table_diff();		
			}else{
				$data['show_table'] = "";
				}
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
				
		$this->load->view('admin_views/laporan/param_fkc_baby', $data);
		}
	}
/*
------------------------------
end coding
------------------------------
*/
	function fsc(){
      
	  if($_POST) {
            $data['id_cabang'] = $this->input->post('intid_cabang');
            $data['nama_cabang'] = $this->input->post('id_cabang');
            $data['bulan'] = $this->input->post('month');
            $data['parent'] = $this->input->post('strkode_dealer');
            $data['unit'] = $this->input->post('id_unit');
            $data['nama_unit'] = $this->input->post('nama_unit');
            $data['nama_bulan'] = $this->nama_bulan($data['bulan']);
            $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($data['parent']);
			
          //reguler
            $data['Reg'] = $this->Penjualan_model->get_reguler($data['id_cabang'], $data['bulan']);
            $data['RegDealer'] = $this->Penjualan_model->get_reguler_dealer($data['id_cabang'], $data['bulan']);

            //Hut
            $data['Hut'] = $this->Penjualan_model->get_hut($data['id_cabang'], $data['bulan']);
            $data['HutDealer'] = $this->Penjualan_model->get_hut_dealer($data['id_cabang'], $data['bulan']);
			
			//Challenge
            $data['Cal'] = $this->Penjualan_model->get_cal($data['id_cabang'], $data['bulan']);
            $data['CalDealer'] = $this->Penjualan_model->get_cal_dealer($data['id_cabang'], $data['bulan']);
			
			//Trade In
            $data['tin'] = $this->Penjualan_model->get_tin($data['id_cabang'], $data['bulan']);
            $data['tinDealer'] = $this->Penjualan_model->get_tin_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 Hut
            $data['ifi'] = $this->Penjualan_model->get_ifi($data['id_cabang'], $data['bulan']);
            $data['ifiDealer'] = $this->Penjualan_model->get_ifi_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 
            $data['ifo'] = $this->Penjualan_model->get_ifo($data['id_cabang'], $data['bulan']);
            $data['ifoDealer'] = $this->Penjualan_model->get_ifo_dealer($data['id_cabang'], $data['bulan']);

			//Netto 
            $data['net'] = $this->Penjualan_model->get_net($data['id_cabang'], $data['bulan']);
            $data['netDealer'] = $this->Penjualan_model->get_net_dealer($data['id_cabang'], $data['bulan']);
			
			//SpecialPrice 
            $data['sp'] = $this->Penjualan_model->get_sp($data['id_cabang'], $data['bulan']);
            $data['spDealer'] = $this->Penjualan_model->get_sp_dealer($data['id_cabang'], $data['bulan']);
			
			//Point 
            $data['p'] = $this->Penjualan_model->get_p($data['id_cabang'], $data['bulan']);
            $data['pDealer'] = $this->Penjualan_model->get_p_dealer($data['id_cabang'], $data['bulan']);

			//Metal 50%
            $data['m50'] = $this->Penjualan_model->get_m50($data['id_cabang'], $data['bulan']);
            $data['m50Dealer'] = $this->Penjualan_model->get_m50_dealer($data['id_cabang'], $data['bulan']);
			
			$data['getFeeSc'] = $this->Penjualan_model->get_dealer_cabang($this->input->post('intid_cabang'), $data['bulan']);
			$data['data_cabang'] = $this->Penjualan_model->get_cabang($this->input->post('intid_cabang'));
            $this->load->view('admin_views/laporan/print_fee_sc', $data);
			
        }else {
			
			$cabang = $this->User_model->getCabang($this->session->userdata('username'));
			$nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
			$data['cabang'] = $nm_cabang[0]->strnama_cabang;
			$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
					
			$this->load->view('admin_views/laporan/param_fsc', $data);
		}
    }
	function babyfsc(){
	if($_POST){
/*
	$data['id_cabang'] = $this->input->post('intid_cabang');
            $data['nama_cabang'] = $this->input->post('id_cabang');
            $data['bulan'] = $this->input->post('month');
            $data['parent'] = $this->input->post('strkode_dealer');
            $data['unit'] = $this->input->post('id_unit');
            $data['nama_unit'] = $this->input->post('nama_unit');
            $data['nama_bulan'] = $this->nama_bulan($data['bulan']);
            $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($data['parent']);
			
          //reguler
            $data['Reg'] = $this->Penjualan_model->get_reguler($data['id_cabang'], $data['bulan']);
            $data['RegDealer'] = $this->Penjualan_model->get_reguler_dealer($data['id_cabang'], $data['bulan']);

            //Hut
            $data['Hut'] = $this->Penjualan_model->get_hut($data['id_cabang'], $data['bulan']);
            $data['HutDealer'] = $this->Penjualan_model->get_hut_dealer($data['id_cabang'], $data['bulan']);
			
			//Challenge
            $data['Cal'] = $this->Penjualan_model->get_cal($data['id_cabang'], $data['bulan']);
            $data['CalDealer'] = $this->Penjualan_model->get_cal_dealer($data['id_cabang'], $data['bulan']);
			
			//Trade In
            $data['tin'] = $this->Penjualan_model->get_tin($data['id_cabang'], $data['bulan']);
            $data['tinDealer'] = $this->Penjualan_model->get_tin_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 Hut
            $data['ifi'] = $this->Penjualan_model->get_ifi($data['id_cabang'], $data['bulan']);
            $data['ifiDealer'] = $this->Penjualan_model->get_ifi_dealer($data['id_cabang'], $data['bulan']);
			
			//1 Free 1 
            $data['ifo'] = $this->Penjualan_model->get_ifo($data['id_cabang'], $data['bulan']);
            $data['ifoDealer'] = $this->Penjualan_model->get_ifo_dealer($data['id_cabang'], $data['bulan']);

			//Netto 
            $data['net'] = $this->Penjualan_model->get_net($data['id_cabang'], $data['bulan']);
            $data['netDealer'] = $this->Penjualan_model->get_net_dealer($data['id_cabang'], $data['bulan']);
			
			//SpecialPrice 
            $data['sp'] = $this->Penjualan_model->get_sp($data['id_cabang'], $data['bulan']);
            $data['spDealer'] = $this->Penjualan_model->get_sp_dealer($data['id_cabang'], $data['bulan']);
			
			//Point 
            $data['p'] = $this->Penjualan_model->get_p($data['id_cabang'], $data['bulan']);
            $data['pDealer'] = $this->Penjualan_model->get_p_dealer($data['id_cabang'], $data['bulan']);
			
			$data['getFeeSc'] = $this->Penjualan_model->get_dealer_cabang($this->input->post('intid_cabang'), $data['bulan']);
			$data['data_cabang'] = $this->Penjualan_model->get_cabang($this->input->post('intid_cabang'));
           */
	 $this->load->view('admin_views/laporan/print_fee_sc', $data);
		
		}else{

		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
			$nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
			$data['cabang'] = $nm_cabang[0]->strnama_cabang;
			$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
					
			$this->load->view('admin_views/laporan/param_babyfsc', $data);

	}

	}
	
	function jum_children ($induk, $level) {
    	$query = "select member.intid_dealer, member.strkode_upline, member.strkode_dealer, member.strnama_dealer, sum(nota.inttotal_omset)as inttotal_omset from member left join nota on nota.intid_dealer = member.intid_dealer where member.strkode_upline='$induk' group by member.intid_dealer";
		$result = $this->db->query($query);
		$l = $level;
		if($result->num_rows() > 0):
			foreach($result->result_array() as $row):
					$child = $this->jum_children($row['strkode_dealer'],$level+1);
					if($child > 1 && $l < $child) $l = $child;	
			endforeach;
		endif;
    	
		
		return $l;
					
	}
	//diubah line ikhlas 16mei2013
/*
	function data_penjualan() {
        
        $page=$this->uri->segment(3);
	    $batas=10;
	    if(!$page):
	    $offset = 0;
	    else:
	    $offset = $page;
	    endif;

	   /* $data['nama']="";
		$data['dealer']="";
	    $postkata = $this->input->post('nama');
		$postkata1 = $this->input->post('dealer');
	    if((!empty($postkata))||(!empty($postkata1)))
	    {
	        $data['nama'] = $this->input->post('nama');
			$data['dealer'] = $this->input->post('dealer');
	        $this->session->set_userdata('pencarian_tanggal', $data['nama'], $data['dealer']);
	    }
	    else
	    {
	        $data['nama'] = $this->session->userdata('pencarian_tanggal');
	    }*/
		/*
		$data['nama'] = $this->input->post('nama');
		$data['dealer'] = $this->input->post('dealer');
			
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $id_cabang = $nm_cabang[0]->intid_cabang;
	    $data['datetgl'] = $this->Laporan_model->Cari_tanggal($batas,$offset,$data['nama'], $data['dealer'], $id_cabang);
	    $tot_hal = $this->Laporan_model->tot_hal('nota','datetgl',$data['nama'], $data['dealer']);

	    $config['base_url'] = base_url() . 'laporan/data_penjualan/';
	    $config['total_rows'] = $tot_hal->num_rows();
	    $config['per_page'] = $batas;
	    $config['uri_segment'] = 3;
	    $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
	    $this->pagination->initialize($config);
	    $data["pagination"] =$this->pagination->create_links();

	    $this->load->view('admin_views/laporan/data_penjualan', $data);
    }
	*/
	function hapus($intno_nota)
	{
		$id = $this->Laporan_model->selectnota($intno_nota);
		for($i=0;$i<sizeof($id);$i++) {
			//pengembalian barang ke stok
			$where_pr['intid_barang'] = $id[$i]->intid_barang;
			$where_pr['intid_cabang'] = 1;
			$qty = $id[$i]->intquantity;
			$get_stokpusat = $this->Laporan_model->get_stokpusat($where_pr);
			$qtyendbefore = $get_stokpusat->row()->intqty_end;
			$update_stokcab['intqty_end'] = $qtyendbefore + $qty;
			$update_stokcab['tanggal']=  date("Y-m-d");
			$update_stokcab['intqty_in']=  $qty;
			$week = $this->Penjualan_model->selectWeek();
        	$update_stokcab['intid_week'] = $week[0]->intid_week;
			$update_stokcab['intid_barang'] = $id[$i]->intid_barang;
			$update_stokcab['intqty_begin'] = $qtyendbefore;
			$update_stokcab['intid_cabang'] = 1;
			$where_stokcab['intid_barang'] = $id[$i]->intid_barang;
			$where_stokcab['intid_cabang'] = 1;
			$this->Laporan_model->updateStokCab($where_stokcab, $update_stokcab);
			$this->Laporan_model->insertstokhistorycab($update_stokcab);
		}
		
		$this->Laporan_model->hapus($intno_nota);
		redirect('laporan/data_penjualan');
	}
	
	function viewNota($intno_nota)
	{
		$data['default'] = $this->Penjualan_model->LaporanNota($intno_nota);
        $this->load->view('admin_views/laporan/cetak_nota', $data);
	}
	
	function viewNotaAsi($intno_nota)
	{
		$data['default'] = $this->Penjualan_model->LaporanNota($intno_nota);
        $this->load->view('admin_views/laporan/cetak_nota_asi', $data);
	}
	
	function pemenang() {
       $this->load->view('admin_views/laporan/pemenang');
    }
	
	function excel_menang(){
		$bln = $this->input->post('bulan');
		$thn = $this->input->post('tahun');
		$data['bln'] = $bln;
		$data['tahun'] = $thn;
		$sisa_blmmenang = $this->Penjualan_model->getJumlahArisan($bln, $thn);
		
		if($sisa_blmmenang->jum_sisa == 0){
			$sisa=1;
		}else{
			$sisa=$sisa_blmmenang->jum_sisa;
		}
		$data['sisa'] = $sisa;
		$data['default'] = $this->Laporan_model->get_pemenang_arisan($bln, $thn);
		$this->load->view('admin_views/laporan/excel_pemenang', $data);
	}
	
	function rekappv()
	{
		$jpenjualan = $this->Penjualan_model->selectJPenjualan();
		foreach ($jpenjualan as $g)
		{
			$data['intid_jpenjualan'][]	 	= $g->intid_jpenjualan;
			$data['strnama_jpenjualan'][] 	= $g->strnama_jpenjualan;
		}
		$this->load->view('admin_views/laporan/param_rekappv', $data);
	}
	
	function cetakrekappv()
	{
		$data['default'] = $this->Laporan_model->rekapPV($this->input->post('tglstart'), $this->input->post('tglend'), $this->input->post('intid_jpenjualan'));
        $this->load->view('admin_views/laporan/rekappv', $data);
	}
	
	function komisi()
	{
		$week = $this->Laporan_model->selectWeek();
		foreach ($week as $g)
		{
			$data['id'][]	 	= $g->id;
			$data['intid_week'][] 	= $g->intid_week;
		}
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/param_komisi', $data);
	}
	
	function cetak_komisi()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$cabang = $nm_cabang[0]->intid_cabang;
		
		$data['default'] = $this->Laporan_model->get_CetakPenjualanKomisi($this->input->post('intid_week'),$this->input->post('intid_cabang'));
		
		$this->load->view('admin_views/laporan/komisi', $data);
		
	}
	
	function sales()
	{
		$week = $this->Laporan_model->selectWeek();
		foreach ($week as $g)
		{
			$data['id'][]	 	= $g->id;
			$data['intid_week'][] 	= $g->intid_week;
		}
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
		$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$this->load->view('admin_views/laporan/param_sales', $data);
	}
	
	function sales_cetak()
	{
		$nm_cabang = $this->Cabang_model->select($this->input->post('intid_cabang'));
	
		$data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		$cabang = $nm_cabang[0]->intid_cabang;
		$data['default'] = $this->Laporan_model->get_CetakSales($this->input->post('intid_week'),$this->input->post('intid_cabang'));
		
		//$this->load->view('admin_views/laporan/sales', $data);
		//tambahan dengan kondisi minus (-)
		$this->load->view('halaman/SALES_VER1', $data);
	
	}
	/////line ikhlas 12042013///
	function data_penjualan_nota_hadiah() {
        
        $page=$this->uri->segment(3);
	    $batas=10;
	    if(!$page):
	    $offset = 0;
	    else:
	    $offset = $page;
	    endif;

	   /* $data['nama']="";
		$data['dealer']="";
	    $postkata = $this->input->post('nama');
		$postkata1 = $this->input->post('dealer');
	    if((!empty($postkata))||(!empty($postkata1)))
	    {
	        $data['nama'] = $this->input->post('nama');
			$data['dealer'] = $this->input->post('dealer');
	        $this->session->set_userdata('pencarian_tanggal', $data['nama'], $data['dealer']);
	    }
	    else
	    {
	        $data['nama'] = $this->session->userdata('pencarian_tanggal');
	    }*/
		$data['nama'] = $this->input->post('nama');
		$data['dealer'] = $this->input->post('dealer');
			
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);

        $id_cabang = $nm_cabang[0]->intid_cabang;
	    $data['datetgl'] = $this->Laporan_model->Cari_tanggal_nota_hadiah($batas,$offset,$data['nama'], $data['dealer'], $id_cabang);
	    $tot_hal = $this->Laporan_model->tot_hal('nota_hadiah','datetgl',$data['nama'], $data['dealer']);

	    $config['base_url'] = base_url() . 'laporan/data_penjualan_nota_hadiah/';
	    $config['total_rows'] = $tot_hal->num_rows();
	    $config['per_page'] = $batas;
	    $config['uri_segment'] = 3;
	    $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
	    $this->pagination->initialize($config);
	    $data["pagination"] =$this->pagination->create_links();

	    $this->load->view('admin_views/laporan/data_penjualan_nota_hadiah', $data);
    }
	
	function viewNotaHadiah($intid_nota)
	{
		//$id = $this->uri->segment(3);
		//echo "id : ".$id;
		//$max = $this->Penjualan_model->get_MaxNotaHadiah()->result();
        //$id = $max[0]->intid_nota;
        //$ada = $this->Penjualan_model->get_CetakNotaHadiah($id);
        $data['default'] = $this->Penjualan_model->get_CetakNotaHadiah($intid_nota);
        //echo "intid_nota : ".$intid_nota;
		$this->load->view('admin_views/penjualan/cetak_notahadiah', $data);
		
		//$data['default'] = $this->Penjualan_model->LaporanNota($intno_nota);
        //$this->load->view('admin_views/laporan/cetak_nota', $data);
	}
	function all_or($intid_cabang){
		$temp = $this->Laporan_model->all_or_dealer($intid_cabang,'04');
		echo $temp;
	}
	//line ikhlas16mei diganti dengan sebelum,nya
	function data_penjualan() {
      
		$cabang = $this->User_model->getCabang($this->session->userdata('username'));
        $nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
        $data['cabang'] = $nm_cabang[0]->strnama_cabang;
        $data['id_cabang'] = $nm_cabang[0]->intid_cabang;
		if($_POST){
		 	$postkata = $this->input->post('tanggal');
			$postkata1 = $this->input->post('dealer');
			$postkata2 = $this->input->post('nonota');
			$opt = $this->input->post('click');
			$check = $this->input->post('check');
			if($opt[0] == 1){
				//echo "echo check : ".$check[0].",".$check[1]."";
				
				if(!empty($check[0]) && empty($check[1])){
					$data['datetgl'] = $this->Laporan_model->Show_list_data_penjualan_kondisi($check[0], $postkata, $data['id_cabang']);
				}elseif(!empty($check[1]) && empty($check[0])){
					$data['datetgl'] = $this->Laporan_model->Show_list_data_penjualan_kondisi($check[1], $postkata1,  $data['id_cabang']);
				}else{
					$data['datetgl'] = $this->Laporan_model->Show_list_data_penjualan_dealer($postkata, $postkata1,  $data['id_cabang']);
				}
				//	$data['datetgl'] = $this->Laporan_model->Show_list_data_penjualan_dealer($postkata, $postkata1,  $data['id_cabang']);
			}elseif($opt[0] == 2){
				//echo "opt 2";
				$data['datetgl'] = $this->Laporan_model->Show_list_data_penjualan_nota($postkata2,  $data['id_cabang']);
			}
		}else{
			$data['datetgl'] = $this->Laporan_model->Show_list_data_penjualan_this_day(date('Y-m-d'),$data['id_cabang']);
		}		
		$this->load->view('admin_views/laporan/data_penjualan_no_nota', $data);
		
    }
	/**
	* @param cetak_ormothermanager 
	* input,output
	* desc : digunakan untuk menghitung off reading mother manager. 
	* author	: ikhlas, ifirlana@gmail.com 
	* created	: 8 Juni 2013
	* responsible	: bu elisabeth
	*/
		function cetak_ormothermanager(){
		$baby = array();
		 $cont = 0;
		
			$cabang = $this->User_model->getCabang($this->session->userdata('username'));
			$nm_cabang = $this->Cabang_model->select($cabang[0]->intid_cabang);
	
			$data['cabang'] = $nm_cabang[0]->strnama_cabang;
			$data['id_cabang'] = $nm_cabang[0]->intid_cabang;
			
			$this->load->view('admin_views/laporan/param_ormothermanager');	
		
	}
	function print_ormothermanager(){
		
		$this->load->model('PO_model_1','PO_M');
		$baby = array();
		$cont = 0;
			$unit =	$this->input->post('id_unit');
			$bulan = $this->input->post('bulan');
			$kode_dealer = $this->input->post('strkode_dealer');
			$data['baby'] = $this->Penjualan_model->jumlahbaby_manager($unit,$bulan);
			$tahun = date('Y');
			
			
			$data['nama_bulan'] = $this->nama_bulan($bulan);
			$data_omset = $this->Penjualan_model->get_Omset($kode_dealer, $bulan);
			$unit = $this->Penjualan_model->get_data('intid_unit','strkode_dealer',$kode_dealer,'member');
			
			$data['data_pv_manager'] = $this->Penjualan_model->get_unit_or($kode_dealer, $bulan, $unit[0]->intid_unit);
			$data['data_omset'] = $this->Penjualan_model->get_Omset($kode_dealer, $bulan);
			$data['data_omset_group'] = $this->Penjualan_model->get_Omset_Group($kode_dealer, $bulan);
			$data['nama_dealer'] = $this->Penjualan_model->getDealerByName($kode_dealer);
			$data['rekrut'] = $this->Penjualan_model->getRekrut($kode_dealer, $bulan);
			$data['id_bulan'] = $bulan;
				$datatemp['month']	=	$bulan;
			$data['get_periode'] = $this->PO_M->get_periode($datatemp);
		$this->load->view('admin_views/laporan/print_or_mothermanager',$data);			
	}
	//laporan dealer or all cabang 12 juni2013
function print_or_dealer_all() {
        $bulan =  $this->input->post('bulan');
		$data['query'] = $this->Laporan_model->selectAllMemberORCabang($bulan);
		$this->load->view('admin_views/laporan/print_or_dealer_all/head');
		$this->load->view('admin_views/laporan/print_or_dealer_all/print_or_dealer_all_1', $data);
		$this->load->view('admin_views/laporan/print_or_dealer_all/footer');		
    }
	
	function print_ormothermanagerall(){
		    $bulan = $this->input->post('month');
            $nama_bulan = $this->nama_bulan($bulan);
			$data['nama_bulan'] = $nama_bulan;
			$data['bulan'] = $bulan;
			//$data['data_or_manager'] = $this->Penjualan_model->get_manager_unit($bulan);
			$data['data_or_manager'] = $this->Penjualan_model->get_manager_unit($bulan);
						
			$a = $bulan + 1;
			if($a == 13) {
				$b = 1;
			}else {
				$b = $a;
			}
			$aa = $bulan + 2;
			if($aa == 14) {
				$c = 2;
			}else {
				$c = $aa;
			}
			
			$nama_bulan = $this->nama_bulan($bulan);
			$nama_bulan1 = $this->nama_bulan($b);
			$nama_bulan2 = $this->nama_bulan($c);
			$thn = date('Y');
			$data['weeks'] = $this->Cm_model->cek_bulan($bulan, $thn);
			$this->load->view('admin_views/laporan/view_ormanager_kewajiban',$data);
	}
	//untuk pracm
	/**
	* @param cetak_orcm
	*/
	function cetak_orcm(){
		$this->load->view('admin_views/laporan/param_cetak_orcm');
	}
	function print_or_cm(){
		$this->load->model('Ranting_model');
		$kode_dealer =  $this->input->post('strkode_dealer');
		$bulan =  $this->input->post('bulan');
		
		$data['bulan']	=	$bulan;
		$var			=	$this->Ranting_model->get_datacalon_manager($kode_dealer);
		$data['calon_manager']	= $var;
		$temp = $var[0]->bulan;
		$data['temp_bulan'] = $temp+1;
		$data['nama_bulan']		= $this->nama_bulan($bulan);
		$data['nama_bulan_pengejaran']		= $this->nama_bulan($temp);
        $data['data_anak'] = $this->Ranting_model->get_Anak_Pengejaran($kode_dealer, $bulan,$data['temp_bulan']);
		$data['data_omset'] = $this->Ranting_model->get_Omset_Pengejaran($kode_dealer, $bulan,$data['temp_bulan']);
        $data['nama_dealer'] = $this->Penjualan_model->getDealerByName($kode_dealer);

        $this->load->view('admin_views/laporan/print_or_pracm', $data);

	}
	function print_boom_cm_ranting(){
		$this->load->model('sword_model','SM');
		//$data['dataTemp']	=	$this->SM->excalibur($this->input->post('intid_dealer'),$this->input->post('tglstart'),$this->input->post('tglend'));
		$data['tglawal'] = $this->input->post('tglstart');
		$data['tglakhir'] = $this->input->post('tglend');
		$pilihan = $this->input->post('pilihan');
		$data['dataTemp']	=	$this->SM->HonjoMasamune($this->input->post('intid_dealer'),$this->input->post('tglstart'),$this->input->post('tglend'));
		if($pilihan == 2){
			$this->load->view('admin_views/laporan/halaman_boom',$data);
		}elseif($pilihan == 3){
			$this->load->view('admin_views/laporan/halaman_boom_omset_unit',$data);
		}
	}
}
?>
